﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TSharp.Core.Authorization.Control;
using TSharp.Core.Authorization.Control.Impl;

namespace TSharp.Core.Authorization.Resources
{
    #region 注释
    /* ====================
     * 作者：wangyao
     * 创建时间：2013/5/22 10:27:50
     * ====================
     */
    #endregion
    /// <summary>
    /// 资源的种类划分类，描述一类资源的相关信息，包括基本信息，权限等,描述该类资源全部特征，定义资源关系访问抽象方法。
    /// </summary>
    public abstract class ResourceCategory
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        protected ResourceCategory(string key, int order, string title)
        {
            this.code = key;
            this.Order = order;
            this.title = title;
            this.authorityJudger = new AuthorityJudgerImpl(this);
            this.controlManager = new ControlManagerImpl(this);
        }

        /// <summary>
        /// 唯一标识
        /// </summary>
        public readonly string code;

        /// <summary>
        /// 标题
        /// </summary>
        public readonly string title;

        /// <summary>
        /// 参与者类型
        /// </summary>
        public List<string> ActorTypes { get; protected set; }

        /// <summary>
        /// 操作集合
        /// </summary>
        private OperationSet operationSet;

        /// <summary>
        /// 操作集合
        /// </summary>
        public OperationSet OperationSet
        {
            get
            {
                return operationSet;
            }
            protected set
            {
                this.operationSet = value;
            }
        }

        /// <summary>
        /// 列表显示顺序
        /// </summary>
        public int Order { get; set; }

        private IAuthorityJudger authorityJudger;

        /// <summary>
        /// 权限判断接口
        /// </summary>
        public IAuthorityJudger AuthorityJudger
        {
            get { return authorityJudger; }
            internal set
            {
                authorityJudger = value;
            }
        }

        private IControlManager controlManager;

        /// <summary>
        /// 获取控制访问类
        /// </summary>
        public IControlManager ControlManager
        {
            get { return this.controlManager; }
            internal set
            {
                this.controlManager = value;
            }
        }

        /// <summary>
        /// 获取资源
        /// </summary>
        public abstract IResource GetResource(Guid actorId, Guid resourceId);

        /// <summary>
        /// 获取该类资源或资源组的一级节点
        /// </summary>
        public abstract List<IResource> GetRootResource(Guid actorId);

        /// <summary>
        /// 获取资源或资源分组的子资源
        /// </summary>
        public abstract List<IResource> GetChildResource(Guid actorId, Guid resourceId);

        /// <summary>
        /// 获取资源的父节点
        /// </summary>
        /// <param name="actorId">The actor id.</param>
        /// <param name="resourceId">The resource id.</param>
        /// <returns>IResourceGroup.</returns>
        public abstract IResourceGroup GetParentResource(Guid actorId, Guid resourceId);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="actorId"></param>
        /// <param name="resourceId"></param>
        /// <returns></returns>
        public abstract bool HasChildResource(Guid actorId, Guid resourceId);
    }
}
